class EmailValidator < ActiveModel::Validator
  
  def validate(record)
    record.errors[:email] << "Formato de email invalido" unless formato_email(record.email)
  end
  
  def formato_email(email)
    regex = %r{^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$}xi
    email =~ regex
  end
  
end